package com.example.testcourse3;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class GuessRightServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        GuessGame game = (GuessGame) request.getSession().getAttribute("game");
        int numberOfGuesses = game.getNumberOfGuesses();
        request.setAttribute("numberOfGuesses", numberOfGuesses);
        game.resetGame(); // 重新开始游戏，生成新的随机数
        RequestDispatcher view = request.getRequestDispatcher("/right.jsp");
        view.forward(request, response);
    }
}